public class test {
    public static void main(String[] args) {
//        a apple = new a();
//        apple.hehe();
//        b boy = new b();
//        boy.hehe();
//        System.out.println(boy.haha);
//
        Solution s = new Solution();
        s.countSpecialNumbers(20);
    }
}

class Solution {
    public int countSpecialNumbers(int n) {
        String str = n + "";
        int num = str.length();
        int a = str.charAt(0) - 48;
        if(num <= 1)
            return a;
        int b = (num - 2) * 9;
        String str2 = "";
        for(int i = 0; i < num; i++)
            str2 += a;
        if(str.compareTo(str2) > 0)
            b += a;
        else
            b += a - 1;
        return n - b;
    }
}
